﻿using Easy.Announcement;
using Microsoft.SharePoint.WebPartPages;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;

namespace Easy.Announcement.EasyAnnIsotopeWebPart
{
    [Serializable]
    [ToolboxItem(false)]
    public class EasyAnnIsotopeWebPart : System.Web.UI.WebControls.WebParts.WebPart
    {
        protected override void CreateChildControls()
        {
            EasyAnnIsotopeUserControl uc = (EasyAnnIsotopeUserControl)Page.LoadControl("~/_CONTROLTEMPLATES/15/Easy.Announcement/EasyAnnIsotopeUserControl.ascx");
            uc.WebPart = this;
            this.Controls.Add(uc);
        }

        public override EditorPartCollection CreateEditorParts()
        {
            ArrayList editorArray = new ArrayList();
            EasyAnnIsotopeEditorPart part = new EasyAnnIsotopeEditorPart() { ID = this.ID + "_editorPart1" };
            editorArray.Add(part);
            WebPartToolPart wpToolPart = new WebPartToolPart() { ID = this.ID + "_wpToolPart" };
            editorArray.Add(wpToolPart);

            CustomPropertyToolPart cpToolPart = new CustomPropertyToolPart() { ID = this.ID + "_cpToolPart" };
            editorArray.Add(cpToolPart);
            EditorPartCollection editorParts = new EditorPartCollection(editorArray);
            return editorParts;
            //return base.CreateEditorParts();
        }

        //public override ToolPart[] GetToolParts()
        //{
        //    ToolPart[] toolparts = new ToolPart[3];
        //    WebPartToolPart wptp = new WebPartToolPart();
        //    CustomPropertyToolPart custom = new CustomPropertyToolPart();
        //    toolparts[0] = custom;
        //    toolparts[1] = wptp;

        //    // This is the custom ToolPart.
        //    toolparts[2] = new EasyAnnIsotopeToolPart();

        //    return toolparts;

        //}


        private const string c_ListNameDefault = "Easy Announcement";
        private string c_ListName = c_ListNameDefault;
        [Category("Easy Settings")]
        [DefaultValue(c_ListNameDefault)]
        [Personalizable(PersonalizationScope.Shared)]
        //[FriendlyNameAttribute("Title of the Announcemnet list")]
        //[Description("Type a string value.")]
        [Browsable(false)]
        //[XmlElement(ElementName = "ListName")]
        public string ListName
        {
            get { return c_ListName; }
            set { c_ListName = value; }
        }

        private const string c_ViewNameDefault = "Published";
        private string c_ViewName = c_ViewNameDefault;
        [Category("Easy Settings")]
        [DefaultValue(c_ListNameDefault)]
        [Personalizable(PersonalizationScope.Shared)]
        [WebDisplayName("View of the list that you want to display.")]
        //[Description("Type a string value.")]
        [Browsable(false)]
        //[XmlElement(ElementName = "View Name")]
        public string ViewName
        {
            get { return c_ViewName; }
            set { c_ViewName = value; }
        }

        private const string c_TitleFieldDefault = "Title";
        private string c_TitleField = c_TitleFieldDefault;
        [Category("Easy Settings")]
        [DefaultValue(c_TitleFieldDefault)]
        [Personalizable(PersonalizationScope.Shared)]
        [WebDisplayName("Announcement Title field")]
        //[Description("Type a string value.")]
        [Browsable(false)]
        //[XmlElement(ElementName = "View Name")]
        public string TitleField
        {
            get { return c_TitleField; }
            set { c_TitleField = value; }
        }

        private const string c_PublishDateFieldDefault = "PublishDate";
        private string c_PublishDateField = c_PublishDateFieldDefault;
        [Category("Easy Settings")]
        [DefaultValue(c_PublishDateFieldDefault)]
        [Personalizable(PersonalizationScope.Shared)]
        [WebDisplayName("Announcement Publish Date field")]
        //[Description("Type a string value.")]
        [Browsable(false)]
        //[XmlElement(ElementName = "View Name")]
        public string PublishDateField
        {
            get { return c_PublishDateField; }
            set { c_PublishDateField = value; }
        }

        private const string c_SummaryFieldDefault = "Summary";
        private string c_SummaryField = c_SummaryFieldDefault;
        [Category("Easy Settings")]
        [DefaultValue(c_SummaryFieldDefault)]
        [Personalizable(PersonalizationScope.Shared)]
        [WebDisplayName("Announcement Summary field")]
        //[Description("Type a string value.")]
        [Browsable(false)]
        //[XmlElement(ElementName = "View Name")]
        public string SummaryField
        {
            get { return c_SummaryField; }
            set { c_SummaryField = value; }
        }

        private const string c_FilterByDefault = "";
        private string c_FilterBy = c_FilterByDefault;
        [Category("Easy Settings")]
        [DefaultValue(c_FilterByDefault)]
        [Personalizable(PersonalizationScope.Shared)]
        [WebDisplayName("Type a field name to filter by (choices field only)")]
        //[Description("Type a string value.")]
        [Browsable(false)]
        //[XmlElement(ElementName = "Filter By")]
        public string FilterByField
        {
            get { return c_FilterBy; }
            set { c_FilterBy = value; }
        }

        private const string c_SortByFieldsDefault = "";
        private string c_SortByFields = c_SortByFieldsDefault;
        [Category("Easy Settings")]
        [DefaultValue(c_SortByFieldsDefault)]
        [Personalizable(PersonalizationScope.Shared)]
        [WebDisplayName("Type a list of field internal names to sort by. e.g. 'title;publishdate;'")]
        [Browsable(false)]
        //[XmlElement(ElementName = "Sort By")]
        public string SortByFields
        {
            get { return c_SortByFields; }
            set { c_SortByFields = value; }
        }

    }
}
